<?php
/**
 * User: yyxi@vip.deyi.com
 * Time: 11:57
 */

namespace Apps\Acp\Services;

use Apps\Acp\Models\Campaign;
use Apps\Common\Constant\CacheKeyConstant;
use Apps\Common\Constant\CacheTimeoutConstant;
use Deyi\Functions\CacheFunction;
use Deyi\Functions\ObjectFunction;

class CampaignService extends Campaign
{
    
    public function getOneByFieldCache($field, $value, $refresh = false)
    {
        $cacheKey = CacheFunction::generateKey(CacheKeyConstant::FANLI_REBATE_CAMPAIGN_FIELD_CACHE_KEY, $field, $value);
        $res = $refresh ? null : static::$_memcached->get($cacheKey);

        if (is_array($res)) {
            return $res;
        }

        $res = $this->getOneByField($field, $value);
        if ($res) {
            $res = ObjectFunction::toAo($res);
            static::$_memcached->set($cacheKey, $res, CacheTimeoutConstant::LOCAL_SMALL_CACHE);
        }

        return $res;
    }

}